package cn.edu.masu._20240928;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @Author xuezipeng
 * @Date 2024-09-28 16:17
 */
public class HomeWork20240928 {
    public static void main(String[] args) {
        System.out.println("请不断输入数字后回车，输入0时结算！");
        Scanner scanner = new Scanner(System.in);
        int sum = 0;
        while(true){
            try{
                int userNumber = scanner.nextInt();
                if(userNumber == 0){
                    break;
                }
                sum += userNumber;
            }catch (InputMismatchException e){
                System.out.println("请输入合法的数字，输入0时结算！");
                scanner.next();
            }
        }
        System.out.println("运算结果 = " + sum);
    }
}
